Column

Chart A

Column

Chart B

Chart C

---
title: "hw4_dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
data("instacart")
instacart = 
  instacart |> 
  as_tibble()
sampled_data = instacart |> 
  sample_n(1000)
```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
instacart |> 
  filter(department == "meat seafood")|> 
  plot_ly(y = ~order_hour_of_day, color = ~aisle, type = "box", colors = "viridis")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

```{r}
sampled_data |> 
  group_by(department) |> 
  mutate(count = n()) |> 
  select(department, count, aisle, product_name) |> 
  filter(count>=100) |> 
    mutate(text_label = str_c("Product name: ", product_name)) |> 
  plot_ly(x = ~department, y = ~ count, color = ~aisle, type = "bar", colors = "viridis", text = ~text_label)|> 
  layout(title = "Order Frequency by Department",
         xaxis = list(title = "Department name"),
         yaxis = list(title = "Order Count"))
```

### Chart C

```{r}
sampled_data |> 
  group_by(aisle) |> 
  mutate(mean_order_hour_of_day = mean(order_hour_of_day), 
         mean_days_since_prior_order = mean(days_since_prior_order)) |> 
   mutate(text_label = str_c("Product name: ", product_name)) |> 
  plot_ly(
    x = ~mean_order_hour_of_day, y = ~mean_days_since_prior_order, type = "scatter", mode = "markers",
    color = ~aisle, text = ~text_label, alpha = 0.5)|> 
  layout(title = "Mean of Order Hour by Mean of Days Since Prior Order",
         xaxis = list(title = "Mean of Order Hour"),
         yaxis = list(title = "Mean of Days Since Prior Order"))
```